window.onload = function() {
	var lis = document.getElementById("tab").getElementsByTagName("li");
	console.log(lis)
	lis[0].className="show"
	var tabDiv = document.getElementById("container").getElementsByTagName("ul")
	console.log(tabDiv)
	for(var i = 0; i < lis.length; i++) {
		lis[i].index = i; //自定义属性，用于关联下面的大盒子
		lis[i].onclick = function() {

			for(var j = 0; j < lis.length; j++) {
				//把所有的button清空类名
				lis[j].className = "";
			}
			//点击的那个盒子添加指定类名
			this.className = "show";
			for(var i = 0; i < tabDiv.length; i++) {
				//先让底下的div全部隐藏
				tabDiv[i].className = "hide";
			}
			//然后给当前所点击按钮相关联的盒子添加指定属性
			tabDiv[this.index].className = "show";
		}
	}

	var mySwiper = new Swiper('.swiper-container', {
		width: window.innerWidth,
		paginationClickable: true,
		loop: true,
		autoplay: 3000,
		autoplayDisableOnInteraction: false,
		// 如果需要分页器
		pagination: '.swiper-pagination'
	})
	/*window.onresize=function(){
		
		var imgPP = document.querySelectorAll('.lb-img')
		var swiperSlide = document.querySelectorAll('.swiper-slide');
		var W = document.body.clientWidth
		for(var i=0;i<imgPP.length;i++){
			imgPP[i].style.width=W+'px';
			swiperSlide[i].style.width=W+'px';
		}
	}*/
	
	
	//选择下单部分的方法
	function hasClass(element, cls) {
		return(' ' + element.className + ' ').indexOf(' ' + cls + ' ') > -1;
	}

	function addClass(ele, cls) {
		if(!hasClass(ele, cls)) {
			ele.className = ele.className == '' ? cls : ele.className + ' ' + cls;
		}
		console.log("addClass")
	}

	function removeClass(ele, cls) {
		if(hasClass(ele, cls)) {
			var newClass = ' ' + ele.className.replace(/[\t\r\n]/g, '') + ' ';
			while(newClass.indexOf(' ' + cls + ' ') >= 0) {
				newClass = newClass.replace(' ' + cls + ' ', ' ');
			}
			ele.className = newClass.replace(/^\s+|\s+$/g, '');
		}
		console.log("removeClass")
	}
	var chooseL = document.getElementById("container").getElementsByClassName("container");
	var choose = document.getElementById("container").getElementsByClassName("choose");
	for(var i = 0; i < choose.length; i++) {
		chooseL[i].index = i;
		chooseL[i].onclick = function() {
			if(!hasClass(choose[this.index], "active")) {
				for(var j = 0; j < choose.length; j++) {
					removeClass(choose[j], "active")
				}
				addClass(choose[this.index], "active");
			} else {
				for(var j = 0; j < choose.length; j++) {
					removeClass(choose[j], "active")
				}
				//				removeClass(choose[this.index], "active");
			}
		}

	}
	
	

}